<?php
/**
 * Junction_Sql_Expression_Builder
 * 
 * Builds SQL queries.
 * 
 * @author Patrick J. Mizer <patrick.mizer@gmail.com>
 */
 
using("Junction_Class_Class");
using("Junction_Sql_Expression_Node");
using("Junction_Sql_Expression_Tree");
using("Junction_Sql_Expression_InOrderTraversal");
 
 
class Junction_Sql_Expression_Builder 
{	
	/**
	 * Junction_Sql_Expression_Builder Constructor
	 * 
	 * Static class.  Do not instantiate.
	 */
	private function __construct() {}
	
	/**
	 * Builds SELECT SQL query.
	 * 
	 * @param Junction_Class_Class
	 * @param Junction_Sql_Expression_Node
	 * @return string SQL query
	 */
	public static function buildSelectSql(Junction_Class_Class $class, 
		Junction_Sql_Expression_Node $node)
	{
		$sql = 'SELECT ';
		$i = 0;
		$fields = $class->getFields();
		
		foreach($fields as $field){
			$sql .= $field->getSqlString();
			if(++$i < $class->getNumFields()){
				$sql .= ',';
			}
		}
		
		$sql .= ' FROM ' . $class->getTable()->getSqlString();
		
		$sql .= ' WHERE ';
		
		$tree = new Junction_Sql_Expression_Tree($node);
		
		$sql .= $tree->traverse(new Junction_Sql_Expression_InOrderTraversal());		
		
		return $sql;
	} 
	
	public static function buildUpdateSql()
	{
		
	}
	
	public static function buildDeleteSql()
	{
		
	}
	
	public static function buildInsertSql()
	{
		
	}
}
?>